const Generator = require('yeoman-generator')

const BUILD_FILES = [ 'gulpfile.js', 'gruntfile.js' ]

module.exports = class extends Generator {
    constructor(args, opts) {
        super(args, opts)
    }

    async prompting() {

        this.answers = {}

        if (!this.config.get('buildFile')) {
            let answers = await this.prompt({
                type: 'list',
                name: 'buildFile',
                message: 'Choose a build file',
                choices: BUILD_FILES,
                default: 'gulpfile.js'
            })
            this.answers.buildFile = answers.buildFile
        }
    }

    configuring() {
        if (this.answers.buildFile) {
            this.config.set('buildFile', this.answers.buildFile)
        }
    }

    composeWithSub() {
        if (this.config.get('buildFile') === 'gulpfile.js') {
            this.composeWith(require.resolve('../gulp'))
        } else if (this.config.get('buildFile') === 'gruntfile.js') {
            this.composeWith(require.resolve('../grunt'))
        }
    }

    writing() {
        this.fs.copy(
            this.sourceRoot(),
            this.destinationRoot(),
        )
    }

    install() {
        this.npmInstall([
            'bootstrap',
            'jquery',
            'popper.js',
        ], { 'save': true })
    }
}